package znbkTestPaperRdqh.presenter;

import android.util.Log;

import znbkListRdqh.IWeekAscensionPresenter;
import com.example.lancooznbk.view.base.ILoadPaperView;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;

import znbkTestPaperInfor.ZnbkPaperDef;
import znbkTestPaperRdqh.activity.WeekAscensionPaperActivity;
import znbkTestPaperRdqh.aip.WeekAscensionPaperApi;
import znbkTestPaperRdqh.entity.WeekAscensionPaperEntity;
import znbkTestPaperRdqh.guide.ReviewPaperGuideActivity;

/**
 * Created by Administrator on 2018\4\2 0002.
 */

public class WeekAscensionPaperPresenter implements IWeekAscensionPresenter {

    private ILoadPaperView view;
    private int PaperFrom;

    public WeekAscensionPaperPresenter(ILoadPaperView view,int paperFrom) {
        this.view = (ILoadPaperView) view;
        this.PaperFrom = paperFrom;
    }

    @Override
    public void getData(boolean isShowLoading) {
        if (isShowLoading) view.showLoading();

        HttpOnNextListener<WeekAscensionPaperEntity> httpOnNextListener = new HttpOnNextListener<WeekAscensionPaperEntity>() {
            @Override
            public void onNext(WeekAscensionPaperEntity weekAscensionPaperEntity) {


                if (weekAscensionPaperEntity.getModelSinglePaperInfo() != null) {
                    view.hideLoading();
                    view.loadPaperData(weekAscensionPaperEntity);
                }else {
                    view.showNoData("暂无内容");
                }
            }


            @Override
            public void onError(Throwable e) {
                super.onError(e);
                view.showNetError();
            }

            @Override
            public void onComplete() {
                super.onComplete();
                Log.d("TML","end: "+System.currentTimeMillis());
            }
        };

        WeekAscensionPaperApi api = null;
        if(PaperFrom== ZnbkPaperDef.FROM_WEEK_ASCENSION_GUIDE) {
            api = new WeekAscensionPaperApi(httpOnNextListener, (ReviewPaperGuideActivity) view);
        }else if(PaperFrom== ZnbkPaperDef.FROM_WEEK_ASCENSION){
            api = new WeekAscensionPaperApi(httpOnNextListener, (WeekAscensionPaperActivity) view);
        }

        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(api);
    }

    @Override
    public void getMoreData() {
        getData(false);
    }

    @Override
    public void getDataByStatus(int position) {
        getData(false);
    }


}